package com.cy.mycomposedemo
import BackHandlerExample
import FlowExample
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
//import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.cy.mycomposedemo.ui.theme.Kotlin2TestTheme

class MainActivity : ComponentActivity() {

    var backPressedCount by   mutableIntStateOf(0)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        enableEdgeToEdge()

        setContent {
            FlowExample()
//            BackHandlerExample()
//            APage()
//            DisposableEffectView()
//            MyLaunchedEffectTest1()
//            MyDisposableEffect1()

//            CounterDemo()

//            val clicked = remember { mutableStateOf(0) }
//            if (clicked.value > 5) {
//                Text(text = "remove TestDisposableEffect")
//            } else {
//                TestDisposableEffect3(clicked)
//            }


        //            Kotlin2TestTheme {
//                Scaffold( modifier = Modifier.fillMaxSize() ) { innerPadding ->
//                    Greeting(
//                        name = "Android",
//                        modifier = Modifier.padding(innerPadding)
//                    )
//                }
//            }
        }
    }

    @SuppressLint("MissingSuperCall")
    override fun onBackPressed() {
        println("back pressed ")
        backPressedCount++
//        super.onBackPressed()
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(
        text = "Hello $name!",
        modifier = modifier
    )
    Greeting1()

}

@Composable
fun Greeting1() {
    Column {
        repeat(4) {
            Text(text = "Hello $it")
        }
    }
}

@Composable
fun GreetingPreview() {
    Kotlin2TestTheme {
        Greeting("Hello Android")
    }
}

var text by mutableStateOf("hello")
var showText by mutableStateOf(true)
/**
 * 后续某个时机对text进行更改 text = "lala"，Text组件会自动更新，利用属性委托来实现，这是kotlin特性
 * showText = false 比 设置是否可见更能提升性能
 */
@Preview(showBackground = true)
@Composable
fun TestPreview() {
    if (showText){
        Text(text = "Hello $text")
    }
}
